#pragma once
#include "project/card_game/req-rsp-http.hpp"

#include "project/web_server/login/req-rsp-http.hpp"
#include "project/web_server/upload/req-rsp-http.hpp"

#include "config.h"

extern const std::string root_path;
extern const std::string PEM;
extern const std::string KEY; 


class Server {
public:
    Server()
        : http_server_(createHttpServer()),
        https_server_(createHttpsServer())
        {}
    
    void start() {
        DBConnectionPool::getInstance()->initialize();
        set_http();
        set_https();
        
        http_server_.SetThreadCount(10);
        http_server_.SetBaseDir(root_path); 

        https_server_.SetThreadCount(10);
        https_server_.SetBaseDir(root_path); 

        http_server_.Listen();
        https_server_.Listen();
        loop_.loop();
    }

private:
    muduo::net::EventLoop loop_;
    server_muduo::HttpServer http_server_;
    server_muduo::HttpServer https_server_;

    server_muduo::HttpServer createHttpServer() 
    {
        return server_muduo::HttpServer(8085, "card_game", &loop_);
    }

    server_muduo::HttpServer createHttpsServer() 
    {
        return server_muduo::HttpServer(8090, "http_to_https", &loop_);
    }




    void set_http()
    {
      
        http_server_.Get("/test", test);
        http_server_.Post("/GetUserID", GetUserID);
        http_server_.Post("/UploadDeckArchive",UploadDeckArchive);
        http_server_.Post("/DownloadOpponentArchive",DownloadOpponentArchive);
        http_server_.Post("/UploadOpponentData",UploadOpponentData);
        http_server_.Post("/MatchOpponent", MatchOpponent);
        http_server_.Post("/DownloadOpponentArchiveInRankMode",DownloadOpponentArchiveInRankMode);
        http_server_.Post("/MatchOpponentWithExtra", MatchOpponentWithExtra);

       

        http_server_.Get(".*", NotFoundHandler);  // 匹配所有未处理路径
        http_server_.Post(".*", NotFoundHandler);
    }

    void set_https()
    {
        //http://81.69.160.7:8090
        https_server_.Post("/UserLogin", UserLogin);
        https_server_.Post("/UserRegister",UserRegister);

        https_server_.Get("/GetGameImages",GetGameImages);
        https_server_.Get("/GetActivityImage",GetActivityImage);

        https_server_.Post("/PostGameData",PostGameData);
        https_server_.Post("/PostActivityImage",PostActivityImage);

        https_server_.Post("/POST_GAME_LIBRARY",POST_GAME_LIBRARY);
       

        https_server_.Get(".*", NotFoundHandler);  // 匹配所有未处理路径
        https_server_.Post(".*", NotFoundHandler);



    }



   

};